/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright(c) 2021 Huawei Technologies Co., Ltd */


#ifndef HIUDK3_CRM_H
#define HIUDK3_CRM_H

#include <linux/types.h>
#include "mpu_cmd_base_defs.h"
#include "hiudk3_crm_adapt.h"

#if defined(HIUDK_ULD) || defined(HIUDK_SDK_ADPT)
/* *
 * @brief hinic3_func_max_qnum - get max nic queue number
 * @param udkdev: device pointer to udkdev
 * @retval non-zero: max nic queue number
 * @retval zero: failure
 */
u16 hiudk_func_max_nic_qnum(void *udkdev);

void hiudk_set_msix_auto_mask_state(void *udkdev, u16 msix_idx, enum hinic3_msix_auto_mask flag);

/* *
 * @brief hiudk_set_msix_state - set msix state
 * @param udkdev: device pointer to udkdev
 * @param msix_idx: msix id
 * @param flag: msix state flag, 0-enable, 1-disable
 */
void hiudk_set_msix_state(void *udkdev, u16 msix_idx, enum hinic3_msix_state flag);

/* *
 * @brief hiudk_misx_intr_clear_resend_bit - clear msix resend bit
 * @param udkdev: device pointer to udkdev
 * @param msix_idx: msix id
 * @param clear_resend_en: 1-clear
 */
void hiudk_misx_intr_clear_resend_bit(void *udkdev, u16 msix_idx, u8 clear_resend_en);

int hiudk_set_interrupt_cfg(void *udkdev, struct interrupt_info interrupt_info, u16 channel);

/* *
 * @brief hiudk_alloc_irqs - alloc irq
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 * @param num: alloc number
 * @param irq_info_array: alloc irq info
 * @param act_num: alloc actual number
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_alloc_irqs(
    void *udkdev, enum hinic3_service_type type, u16 num, struct irq_info *irq_info_array, u16 *act_num);

/* *
 * @brief hiudk_free_irq - free irq
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 * @param irq_id: irq id
 */
void hiudk_free_irq(void *udkdev, enum hinic3_service_type type, u32 irq_id);

/* *
 * @brief hiudk_alloc_ceqs - alloc ceqs
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 * @param num: alloc ceq number
 * @param ceq_id_array: alloc ceq_id_array
 * @param act_num: alloc actual number
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_alloc_ceqs(void *udkdev, enum hinic3_service_type type, int num, int *ceq_id_array, int *act_num);

/* *
 * @brief hiudk_free_irq - free ceq
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 * @param irq_id: ceq id
 */
void hiudk_free_ceq(void *udkdev, enum hinic3_service_type type, int ceq_id);

/* *
 * @brief hiudk_ppf_idx - get ppf id
 * @param udkdev: device pointer to udkdev
 * @retval ppf id
 */
u8 hiudk_ppf_idx(void *udkdev);

/* *
 * @brief hiudk_get_chip_present_flag - get chip present flag
 * @param udkdev: device pointer to udkdev
 * @retval 1: chip is present
 * @retval 0: chip is absent
 */
int hiudk_get_chip_present_flag(const void *udkdev);

/* *
 * @brief hiudk_get_heartbeat_status - get heartbeat status
 * @param udkdev: device pointer to udkdev
 * @retval heartbeat status
 */
u32 hiudk_get_heartbeat_status(void *udkdev);

/* *
 * @brief hiudk_support_nic - function support nic
 * @param udkdev: device pointer to udkdev
 * @param cap: nic service capbility
 * @retval true: function support nic
 * @retval false: function not support nic
 */
bool hiudk_support_nic(void *udkdev, struct nic_service_cap *cap);

/* *
 * @brief hiudk_support_ipsec - function support ipsec
 * @param udkdev: device pointer to udkdev
 * @param cap: ipsec service capbility
 * @retval true: function support ipsec
 * @retval false: function not support ipsec
 */
bool hiudk_support_ipsec(void *udkdev, struct ipsec_service_cap *cap);

/* *
 * @brief hiudk_support_roce - function support roce
 * @param udkdev: device pointer to udkdev
 * @param cap: roce service capbility
 * @retval true: function support roce
 * @retval false: function not support roce
 */
bool hiudk_support_roce(void *udkdev, struct rdma_service_cap *cap);

/* *
 * @brief hiudk_support_fc - function support fc
 * @param udkdev: device pointer to udkdev
 * @param cap: fc service capbility
 * @retval true: function support fc
 * @retval false: function not support fc
 */
bool hiudk_support_fc(void *udkdev, struct fc_service_cap *cap);

/* *
 * @brief hiudk_support_rdma - function support rdma
 * @param udkdev: device pointer to udkdev
 * @param cap: rdma service capbility
 * @retval true: function support rdma
 * @retval false: function not support rdma
 */
bool hiudk_support_rdma(void *udkdev, struct rdma_service_cap *cap);

/* *
 * @brief hiudk_support_ovs - function support ovs
 * @param udkdev: device pointer to udkdev
 * @param cap: ovs service capbility
 * @retval true: function support ovs
 * @retval false: function not support ovs
 */
bool hiudk_support_ovs(void *udkdev, struct ovs_service_cap *cap);

/* *
 * @brief hiudk_support_vbs - function support vbs
 * @param udkdev: device pointer to udkdev
 * @param cap: vbs service capbility
 * @retval true: function support vbs
 * @retval false: function not support vbs
 */
bool hiudk_support_vbs(void *udkdev, struct vbs_service_cap *cap);

/* *
 * @brief hiudk_support_toe - sync time to hardware
 * @param udkdev: device pointer to udkdev
 * @param cap: toe service capbility
 * @retval zero: success
 * @retval non-zero: failure
 */
bool hiudk_support_toe(void *udkdev, struct toe_service_cap *cap);

/* *
 * @brief hiudk_support_ppa - function support ppa
 * @param udkdev: device pointer to udkdev
 * @param cap: ppa service capbility
 * @retval zero: success
 * @retval non-zero: failure
 */
bool hiudk_support_ppa(void *udkdev, struct ppa_service_cap *cap);

/* *
 * @brief hiudk_support_migr - function support migrate
 * @param udkdev: device pointer to udkdev
 * @param cap: migrate service capbility
 * @retval zero: success
 * @retval non-zero: failure
 */
bool hiudk_support_migr(void *udkdev, struct migr_service_cap *cap);

int hiudk_set_ppf_flr_type(void *udkdev, enum hinic3_ppf_flr_type flr_type);

/* *
 * @brief hiudk_set_ppf_tbl_hotreplace_flag - set os hotreplace flag in ppf function table
 * @param udkdev: device pointer to udkdev
 * @param flag : os hotreplace flag : 0-not in os hotreplace 1-in os hotreplace
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_set_ppf_tbl_hotreplace_flag(void *udkdev, u8 flag);

/* *
 * @brief hiudk_get_mgmt_version - get management cpu version
 * @param udkdev: device pointer to udkdev
 * @param mgmt_ver: output management version
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_get_mgmt_version(void *udkdev, u8 *mgmt_ver, u8 version_size, u16 channel);

/* *
 * @brief hiudk_get_fw_version - get firmware version
 * @param udkdev: device pointer to udkdev
 * @param fw_ver: firmware version
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_get_fw_version(void *udkdev, struct hinic3_fw_version *fw_ver, u16 channel);

/* *
 * @brief hiudk_get_bond_create_mode - get bond create mode
 * @param udkdev: device pointer to udkdev
 * @retval bond create mode
 */
u8 hiudk_get_bond_create_mode(void *udkdev);

/* *
 * @brief hiudk_global_func_id - get global function id
 * @param udkdev: device pointer to udkdev
 * @retval global function id
 */
u16 hiudk_global_func_id(void *udkdev);

/* *
 * @brief hiudk_vector_to_eqn - vector to eq id
 * @param udkdev: device pointer to udkdev
 * @param type: service type
 * @param vector: vertor
 * @retval eq id
 */
int hiudk_vector_to_eqn(void *udkdev, enum hinic3_service_type type, int vector);

/* *
 * @brief hiudk_glb_pf_vf_offset - get vf offset id of pf
 * @param udkdev: device pointer to udkdev
 * @retval vf offset id
 */
u16 hiudk_glb_pf_vf_offset(void *udkdev);

/* *
 * @brief hiudk_pf_id_of_vf - get pf id of vf
 * @param udkdev: device pointer to udkdev
 * @retval pf id
 */
u8 hiudk_pf_id_of_vf(void *udkdev);

/* *
 * @brief hiudk_func_type - get function type
 * @param udkdev: device pointer to udkdev
 * @retval function type
 */
enum func_type hiudk_func_type(void *udkdev);

/* *
 * @brief hiudk_get_stateful_enable - get stateful status
 * @param udkdev: device pointer to udkdev
 * @retval stateful enabel status
 */
bool hiudk_get_stateful_enable(void *udkdev);

/* *
 * @brief hiudk_get_timer_enable - get timer status
 * @param udkdev: device pointer to udkdev
 * @retval timer enabel status
 */
bool hiudk_get_timer_enable(void *udkdev);

/* *
 * @brief hiudk_host_oq_id_mask - get oq id
 * @param udkdev: device pointer to udkdev
 * @retval oq id
 */
u8 hiudk_host_oq_id_mask(void *udkdev);

/* *
 * @brief hiudk_host_id - get host id
 * @param udkdev: device pointer to udkdev
 * @retval host id
 */
u8 hiudk_host_id(void *udkdev);

/* *
 * @brief hiudk_func_max_qnum - get host total function number
 * @param udkdev: device pointer to udkdev
 * @retval non-zero: host total function number
 * @retval zero: failure
 */
u16 hiudk_host_total_func(void *udkdev);

/* *
 * @brief hiudk_func_max_qnum - get max queue number
 * @param udkdev: device pointer to udkdev
 * @retval non-zero: max queue number
 * @retval zero: failure
 */
u16 hiudk_func_max_qnum(void *udkdev);

/* *
 * @brief hiudk_er_id - get ep id
 * @param udkdev: device pointer to udkdev
 * @retval ep id
 */
u8 hiudk_ep_id(void *udkdev); /* Obtain service_cap.ep_id */

/* *
 * @brief hiudk_er_id - get er id
 * @param udkdev: device pointer to udkdev
 * @retval er id
 */
u8 hiudk_er_id(void *udkdev); /* Obtain service_cap.er_id */

/* *
 * @brief hiudk_physical_port_id - get physical port id
 * @param udkdev: device pointer to udkdev
 * @retval physical port id
 */
u8 hiudk_physical_port_id(void *udkdev); /* Obtain service_cap.port_id */

/* *
 * @brief hiudk_func_max_vf - get vf number
 * @param udkdev: device pointer to udkdev
 * @retval non-zero: vf number
 * @retval zero: failure
 */
u16 hiudk_func_max_vf(void *udkdev); /* Obtain service_cap.max_vf */

/*
 * @brief hiudk_max_pf_num - get global max pf number
 */
u8 hiudk_max_pf_num(void *udkdev);

/* *
 * @brief hiudk_pcie_itf_id - get pcie port id
 * @param udkdev: device pointer to udkdev
 * @retval pcie port id
 */
u8 hiudk_pcie_itf_id(void *udkdev);

/* *
 * @brief hiudk_vf_in_pf - get vf offset in pf
 * @param udkdev: device pointer to udkdev
 * @retval vf offset in pf
 */
u8 hiudk_vf_in_pf(void *udkdev);

/* *
 * @brief hiudk_cos_valid_bitmap - get cos valid bitmap
 * @param udkdev: device pointer to udkdev
 * @retval non-zero: valid cos bit map
 * @retval zero: failure
 */
int hiudk_cos_valid_bitmap(void *udkdev, u8 *func_dft_cos, u8 *port_cos_bitmap);

/* *
 * @brief hiudk_stateful_init - init stateful resource
 * @param udkdev: device pointer to udkdev
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_stateful_init(void *udkdev);

/* *
 * @brief hiudk_stateful_deinit - deinit stateful resource
 * @param udkdev: device pointer to udkdev
 */
void hiudk_stateful_deinit(void *udkdev);

/* *
 * @brief hiudk_get_card_present_state - get card present state
 * @param udkdev: device pointer to udkdev
 * @param card_present_state: return card present state
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_get_card_present_state(void *udkdev, bool *card_present_state);

/* *
 * @brief hiudk_func_rx_tx_flush - function flush
 * @param udkdev: device pointer to udkdev
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_func_rx_tx_flush(void *udkdev, u16 channel, bool wait_io);

/*
 * @brief hiudk_ceq_num get toe ceq num
 */
u8 hiudk_ceq_num(void *udkdev);

/*
 * @brief hiudk_intr_num get intr num
 */
u16 hiudk_intr_num(void *udkdev);

/*
 * @brief hiudk_flexq_en get flexq en
 */
u8 hiudk_flexq_en(void *udkdev);

/*
 * @brief hiudk_get_fake_vf_info get fake_vf info
 */
int hiudk_get_fake_vf_info(void *hwdev, u8 *fake_vf_vld, u8 *page_bit, u8 *pf_start_bit, u8 *map_host_id);

/**
 * @brief hiudk_fault_event_report - report fault event
 * @param udkdev: device pointer to udkdev
 * @param src: fault event source, reference to enum hinic3_fault_source_type
 * @param level: fault level, reference to enum hinic3_fault_err_level
 */
void hiudk_fault_event_report(void *udkdev, u16 src, u16 level);

/**
 * @brief hiudk_set_func_svc_used_state - set function service used state
 * @param udkdev: device pointer to udkdev
 * @param svc_type: service type
 * @param state: function used state
 * @param channel: channel id
 * @retval zero: success
 * @retval non-zero: failure
 */
int hiudk_set_func_svc_used_state(void *udkdev, u16 svc_type, u8 state, u16 channel);

u32 hiudk_host_pf_num(void *hwdev);

u32 hiudk_host_pf_id_start(void *hwdev);

/* *
 * @brief hiudk_get_slave_bitmap - get slave host bitmap
 * @param udkdev: device pointer to udkdev
 * @param slave_host_bitmap-zero: slave host bitmap
 * @retval zero: failure
 */
int hiudk_get_slave_bitmap(void *hwdev, u8 *slave_host_bitmap);

/* *
 * @brief hiudk_get_slave_host_enable - get slave host enable
 * @param udkdev: device pointer to udkdev
 * @param host_id: get host id
 * @param slave_en-zero: slave is enable
 * @retval zero: failure
 */
int hiudk_get_slave_host_enable(void *udkdev, u8 host_id, u8 *slave_en);

int hiudk_set_host_migrate_enable(void *hwdev, u8 host_id, bool enable);

int hiudk_get_host_migrate_enable(void *hwdev, u8 host_id, u8 *migrate_en);

int hiudk_is_slave_func(const void *hwdev, bool *is_slave_func);

int hiudk_is_master_func(const void *hwdev, bool *is_master_func);

bool hiudk_is_multi_bm(void *hwdev);

bool hiudk_is_slave_host(void *hwdev);

bool hiudk_is_vm_slave_host(void *hwdev);

bool hiudk_is_bm_slave_host(void *hwdev);

bool hiudk_is_guest_vmsec_enable(void *hwdev);

int hiudk_get_vfid_by_vfpci(void *hwdev, struct pci_dev *pdev, u16 *global_func_id);

int hiudk_set_func_nic_state(void *hwdev, struct hinic3_func_nic_state *state);

int hiudk_get_netdev_state(void *hwdev, u16 func_idx, int *opened);

int hiudk_get_dev_cap(void *hwdev);

int hiudk_get_mhost_func_nic_enable(void *hwdev, u16 func_id, bool *en);

int hiudk_mbox_to_host_sync(void *hwdev, enum hinic3_mod_type mod,
			    u8 cmd, void *buf_in, u16 in_size,
			    void *buf_out, u16 *out_size, u32 timeout, u16 channel);

int hiudk_get_func_vroce_enable(void *hwdev, u16 glb_func_idx, u8 *en);

#endif
#endif
